<?php
namespace Admin\Controller;
use Think\Controller;

class OrderController extends Controller{
    public function index(){
        $uid=I('get.all');
        $order=M('orders');
        //====================订单分页==========================
        //查询个数
        $count=$order->count();
        //每页显示3个
        $page = new \Think\Page($count,5);
        //设置页码显示
        $page->setConfig('header', '共 %TOTAL_ROW% 条记录');
        $page->setConfig('first', '首页');
        $page->setConfig('last', '末页');
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $page->setConfig('theme',"共 %TOTAL_ROW% 条记录 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $this->assign('show', $page->show());

        $data=$order->page(I('get.p',1),5)->order('id desc')->select();
        // 3.分配数据
        $this->assign('data', $data);

        // 4.输出模板
        $this->display();
    }

    public function detail()
    {
        $all=I('get.');
        //dump($all);
        $modd=M("orders");
        $orderss=$modd->join("yg_detail ON yg_orders.order_number = yg_detail.order_number")
            ->where("yg_orders.order_number={$all['order_number']}")
            ->select();

        $this->assign("orders",$orderss);
        $this->display();
    }
    public function search(){
        $uid=I('get.all');
        //dump($uid);
        $order=M('orders');
        $data=$order->where('linkman="'.$uid.'" OR state="'.$uid.'"OR order_number="'.$uid.'" OR mobile="'.$uid.'"')
            ->order('order_number desc')
            ->select();
        // 3.分配数据
        $this->assign('data', $data);
        // 4.输出模板
        $this->display('index');
    }
    //===================删除订单================================
    public function del(){

        //实例化
        $mod=M("orders");
        $orders_id=$_GET['id'];

        $s=$mod->where('id="'.$orders_id.'"')->delete();
        if($s){
            //$this->success("删除成功",U("Order/index"));
            $JSONObject['code'] =1;
//            //$this->success('修改用户信息成功',U('Admin/index','id='.I('post.id')));
            exit(json_encode($JSONObject));

        }else{
            //$this->error("删除失败");
            $JSONObject['code'] =0;
//            //$this->success('修改用户信息成功',U('Admin/index','id='.I('post.id')));
            exit(json_encode($JSONObject));
        }
    }

    //==================订单留言========================================
    public function message(){
        $all=I('get.');
        $mod=M("message");
        $news=$mod->select();
        $this->assign('news',$news);
        $this->display();
    }
    public function delmsg(){
        $all=I('get.');
        $mod=M("message");
        $news=$mod->where('id='.$all['id'])->delete();
        if($news){
            //$this->success("删除成功",U("Order/message"));
            $JSONObject['code'] =1;
            exit(json_encode($JSONObject));

        }else{
            $JSONObject['code'] =0;
            exit(json_encode($JSONObject));
        }
    }
    //=================商品评价==============================
    public function comment(){
        $all=I('get.');
        $mod=M("comment");
        $news=$mod->select();
        $this->assign('comm',$news);
        $this->display();

    }
    //================删除评价==============================
    public function delcomm(){
        $all=I('get.');
        $mod=M("comment");
        $news=$mod->where('commit_id='.$all['id'])->delete();
        if($news){
            $this->success("删除成功",U("Order/comment"));

        }else{
            $this->error("删除失败");
        }
    }
    //===================评价回复===============================
    public function insert(){
        $this->display();
    }

    public function replay(){
        //实例化回复表
        $replay=M('commentreplay');
        $_POST['addtime']=date('Y-m-d H:i:s',time());
        $a=$_POST['replay_content'];
        if(!$a){
            //$this->error('内容不能为空',U('order/insert'));
            $JSONObject['code'] =3;
            exit(json_encode($JSONObject));
        }
        $replay->create();
        //dump($_POST);
        $res=$replay->add($_POST);
        if($res){
//            $this->success('回复成功',U('order/comment'));
            $JSONObject['code'] =1;
            exit(json_encode($JSONObject));
        }else{
//            $this->error('回复失败',U('order/insert'));
            $JSONObject['code'] =2;
            exit(json_encode($JSONObject));
        }
    }
}
